﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniRlv.COL;

namespace UniRlv.Utility.AppLib
{
    public class DODevice
    {
        public LineDevice Device { get; set; }
        AbtDODevice DODev = null;

        public string ErrorString
        {
            get
            {
                return DODev.ErrorString;
            }
        }

        public DODevice(LineDevice dev)
        {
            this.Device = dev;

            if (dev.portType == (int)port_type.PT_NET)
            {
            }
            else if (dev.portType == (int)port_type.PT_COMM)
            {
                if (dev.deviceType == (int)out_device_type.ODT_RELAY)
                {
                    DODev = new ModbusDevice();
                }
                else if (dev.deviceType == (int)out_device_type.ODT_PLC)
                {
                    DODev = new PLCDevice();
                }
                else if (dev.deviceType == (int)out_device_type.ODT_OTHERS)
                {//微嵌电子继电器卡
                    DODev = new WQBoard();
                }
            }

            DODev.InitString = dev.initString;
        }


        public bool Open()
        {
            return DODev.Open();
        }

        public bool IsOpen()
        {
            return DODev.IsOpen();
        }

        public void Close()
        {
            DODev.Close();
        }

        public void Pause()
        {
            DODev.Pause();
        }

        public void Resume()
        {
            DODev.Resume();
        }

        public void SendData(string s)
        {
            DODev.SendData(s);
        }

        public void Alarm(int nStation, object obj)
        {//1 3 5 7
            DODev.Alarm(nStation, obj);
        }

        public void Pick(int nStation, object obj)
        {//0 2 4 6
            DODev.Pick(nStation, obj);
        }

        public void Flip(int nStation, object obj)
        {
            DODev.Flip(nStation, obj);
        }

        public void Stop(int nStation, object obj)
        {
            DODev.Stop(nStation, obj);
        }
    }
}
